package com.zxl.always.on.display.configs;

import android.text.TextUtils;

import com.zxl.always.on.display.configs.bean.FullScreenBean;
import com.zxl.always.on.display.configs.bean.InternalAdsBean;
import com.zxl.always.on.display.configs.bean.KeyboardBean;
import com.zxl.always.on.display.configs.bean.UpgradeBean;
import com.zxl.always.on.display.configs.sdk.OnlineConfigAgent;
import com.zxl.always.on.display.configs.sdk.OnlineConfigureListener;
import com.zxl.always.on.display.tools.LogUtils;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Administrator on 2016/10/6.
 */

public class AdsConfigsHelper {

    public static final int ADS_TYPE_XM = 1;

    public static final int ADS_TYPE_WAPS = 2;

    private static InternalAdsBean mInternalAdsBean = new InternalAdsBean();

    private static FullScreenBean mFullScreenBean = new FullScreenBean();

    private static KeyboardBean mKeyboardBean = new KeyboardBean();

    /**
     * 刷新数据
     */
    public static void refreshControlInfo() {
        OnlineConfigAgent.getInstance().updateOnlineConfig(new OnlineConfigureListener() {
            @Override
            public void onDataReceived(JSONObject jsonObject) {
                LogUtils.d("jsonObject : " + jsonObject);
                mInternalAdsBean.parse();
                mInternalAdsBean.parseContent();
                mFullScreenBean.parse();
                mKeyboardBean.parse();
            }
        });
    }

    public static InternalAdsBean getInternalAdsBean() {
        return mInternalAdsBean;
    }

    public static FullScreenBean getFullScreenBean() {
        return mFullScreenBean;
    }

    public static KeyboardBean getKeyboardBean() {
        return mKeyboardBean;
    }

    public static UpgradeBean getUpgradeInfo() {
        String upgrade = getConfigParams("upgrade");
        if (!TextUtils.isEmpty(upgrade)) {
            try {
                JSONObject jsonObject = new JSONObject(upgrade);
                UpgradeBean upgradeBean = new UpgradeBean();
                upgradeBean.parseJson(jsonObject);
                return upgradeBean;
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    public static String getConfigParams(String key) {
        return OnlineConfigAgent.getInstance().getConfigParams(key);
    }
}
